﻿Imports System.Data
Imports DevExpress.XtraGrid.Columns
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraGrid
Imports DevExpress.XtraEditors
Imports DevExpress.XtraGrid.Views.Base
Imports DevExpress.XtraSplashScreen

Public Class PhieuNhap1
     Private state As Integer '0 default 1 tao moi 2 sua
    Private Sub setReadonly(ByVal b As Boolean)
        Me.MaTextEdit.Properties.ReadOnly = b
        Me.NhacungcapSearchLookUpEdit.Properties.ReadOnly = b
        Me.NghiepvuTextEdit.Properties.ReadOnly = b
        Me.SohoadonTextEdit.Properties.ReadOnly = b
        Me.NgayhoadonDateEdit.Properties.ReadOnly = b
        Me.NgaynhapDateEdit.Properties.ReadOnly = b
        Me.NgaythanhtoanDateEdit.Properties.ReadOnly = b
        Me.DiachiTextEdit.Properties.ReadOnly = b
        Me.ThuesuatTextEdit.Properties.ReadOnly = b
        If b Then
            Me.IGridView1.OptionsBehavior.Editable = False
        Else
            Me.IGridView1.OptionsBehavior.Editable = True
        End If
        If b Then 'trong trạng thái readonly  thì không cho nhập và dòng trống thêm ở cuối
            Me.IGridView1.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.None
        Else  'cho thêm dòng trống ở cuối (khác form đơn - bỏ dòng : And State = 1)
            Me.IGridView1.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.Bottom
        End If
        If b Then
            'dxprovidervalidation
            Me.DxValidationProvider1.ValidationMode = DXErrorProvider.ValidationMode.Auto
            setButtonTrangThaiSua(False)
        Else
            Me.DxValidationProvider1.ValidationMode = DXErrorProvider.ValidationMode.Auto
            setButtonTrangThaiSua(True)
        End If
    End Sub
    Private Sub setButtonTrangThaiSua(ByVal b As Boolean) 'set nút lưu và xóa - khi ở trạng thái sửa thì mới cho phép thao tác trên nó (enable = true) - các trạng thái khác thì không cho (enable = false)
        Me.BarButtonItemLuu.Enabled = b
        Me.BarButtonItemXoa.Enabled = b
        If b Then 'xử lý nút sửa (nếu nút lưu - xóa cho phép thì sửa ko cho phép và ngược lại)
            Me.BarButtonItemSua.Enabled = False
        Else
            Me.BarButtonItemSua.Enabled = True
        End If
        setButtonChiTietTrangThaiSua(b)
    End Sub
    Private Sub setButtonChiTietTrangThaiSua(ByVal b As Boolean)
        Me.BarButtonItemTaoMoiChiTiet.Enabled = b
        Me.BarButtonItemXoaChiTiet.Enabled = b
        Me.BarButtonItemHuyThayDoiChiTiet.Enabled = b
    End Sub

    Private Sub BarButtonItemTaoMoi_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemTaoMoi.ItemClick
        Try
            Me.setReadonly(False)
            Me.MaTextEdit.Focus()
            Me.NhapBindingSource.AddNew()
            Me.state = 1
        Catch ex As Exception

        End Try
    End Sub

    Private Sub HangHoa_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        SplashScreenManager.ShowForm(GetType(WaitForm1))
        Me.KhachhangTableAdapter.Fill(Me.PcvgppDataSet.khachhang)
        Me.NhapTableAdapter.Fill(Me.PcvgppDataSet.nhap)
        Me.NhapchitietTableAdapter.Fill(Me.PcvgppDataSet.nhapchitiet)
        Me.HanghoaTableAdapter.Fill(Me.PcvgppDataSet.hanghoa)
        'Me.Hanghoa_donvitinhTableAdapter.Fill(Me.PcvgppDataSet.hanghoa_donvitinh)
        Me.setReadonly(True)
        Me.IGridView1.BestFitColumns()
        Me.NhapBindingSource.MoveLast()
        Me.state = 0
    End Sub

    Private Sub BarButtonItemLuu_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemLuu.ItemClick
        Try
            Me.IGridView1.CloseEditor()
            Me.NhapBindingSource.EndEdit()
            Me.FKnhapchitietnhapBindingSource.EndEdit()
            If Me.PcvgppDataSet.HasChanges Then
                If DevExpress.XtraEditors.XtraMessageBox.Show("Bạn có muốn 'Lưu' không?", "Nhắc Nhở", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then
                    Me.NhapTableAdapter.Update(Me.PcvgppDataSet.nhap)
                    Me.NhapchitietTableAdapter.Update(Me.PcvgppDataSet.nhapchitiet)
                    Me.setReadonly(True)
                    Me.state = 0
                End If
            Else
                DevExpress.XtraEditors.XtraMessageBox.Show("Chưa có thông tin để lưu", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Me.setReadonly(True)
                Me.state = 0
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
    Private Function getKiemTraMaTonTai(ByVal sMa As String) As Boolean 'kiểm tra sự tồn tại của mã - dùng kiểm tra chung với igridview
        If Me.NhapBindingSource.Find("ma", sMa) = -1 Then 'nếu -1 nghĩa là ko tìm đc vị trí trong bindingsource
            Return False
        Else 'còn lại là tìm đc vị trí --> đã tồn tại
            Return True
        End If
    End Function
    'bắt lỗi mã
    Private Sub MaTextEdit_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MaTextEdit.Validating
        If State = 1 Then 'xác định chỉ kiểm tra trong trường hợp tạo mới
            Try
                If Me.getKiemTraMaTonTai(Me.MaTextEdit.EditValue) Then 'kiểm tra mã tồn tại hay chưa ?
                    Me.MaTextEdit.ErrorText = "Mã này đã tồn tại"
                    e.Cancel = True
                End If
            Catch ex As Exception

            End Try
        End If
    End Sub

    Private Sub BarButtonItemSua_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemSua.ItemClick
        Me.setReadonly(False)
        Me.state = 2
    End Sub

    Private Sub BarButtonItemXoa_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemXoa.ItemClick
        If DevExpress.XtraEditors.XtraMessageBox.Show("Bạn có muốn 'Xóa' không?", "Nhắc Nhở", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then
            Me.NhapBindingSource.RemoveCurrent()
            Me.NhapTableAdapter.Update(Me.PcvgppDataSet.nhap)
            Me.setReadonly(True)
            Me.state = 0
        End If
    End Sub

    Private Sub BarButtonItemHuyThayDoi_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemHuyThayDoi.ItemClick
        Me.NhapBindingSource.EndEdit()
        If Me.PcvgppDataSet.HasChanges Then
            If DevExpress.XtraEditors.XtraMessageBox.Show("Bạn có muốn hủy tất cả những thay đổi đang làm không?", "Nhắc Nhở", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then
                Me.PcvgppDataSet.RejectChanges()
            End If
        Else
            DevExpress.XtraEditors.XtraMessageBox.Show("Chưa có thay đổi dữ liệu!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    End Sub

    Private Sub BarButtonItemFirst_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemFirst.ItemClick
        Me.NhapBindingSource.MoveFirst()
    End Sub

    Private Sub BarButtonItem2_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemPrevious.ItemClick
        Me.NhapBindingSource.MovePrevious()
    End Sub

    Private Sub BarButtonItem6_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemNext.ItemClick
        Me.NhapBindingSource.MoveNext()
    End Sub

    Private Sub BarButtonItem7_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemLast.ItemClick
        Me.NhapBindingSource.MoveLast()
    End Sub

    Private Sub BarButtonItemTaoMoiChiTiet_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemTaoMoiChitiet.ItemClick
        Me.IGridView1.Focus()
        Me.IGridView1.AddNewRow()
        Me.IGridView1.FocusedColumn = Me.IGridView1.VisibleColumns(0)
        Me.IGridView1.ShowEditor()

    End Sub

    Private Sub BarButtonItemXoaChiTiet_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemXoaChiTiet.ItemClick
        If DevExpress.XtraEditors.XtraMessageBox.Show("Bạn có muốn xóa dòng đang chọn không?", "Nhắc Nhở", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then
            Me.IGridView1.DeleteRow(Me.IGridView1.FocusedRowHandle)
            Me.IGridView1.UpdateCurrentRow()
            Me.IGridView1.UpdateSummary()
        End If
    End Sub

    Private Sub BarButtonItemHuyThayDoiChiTiet_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemHuyThayDoiChiTiet.ItemClick
        Me.IGridView1.PostEditor()
        Me.IGridView1.CloseEditor()
        Me.NhapchitietBindingSource.EndEdit()
        If PcvgppDataSet.HasChanges Then
            If DevExpress.XtraEditors.XtraMessageBox.Show("Bạn có muốn hủy những thay đổi đang làm không?", "Nhắc Nhở", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then
                Me.PcvgppDataSet.RejectChanges()
            End If
        Else
            DevExpress.XtraEditors.XtraMessageBox.Show("Chưa có thông tin thay đổi!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    End Sub

    Private Sub BarButtonItemFirstChiTiet_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemFirstChiTiet.ItemClick
        Me.NhapchitietBindingSource.MoveFirst()
    End Sub

    Private Sub BarButtonItemPreviousChiTiet_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemPreviousChiTiet.ItemClick
        Me.NhapchitietBindingSource.MovePrevious()
    End Sub

    Private Sub BarButtonItemNextChiTiet_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemNextChiTiet.ItemClick
        Me.NhapchitietBindingSource.MoveNext()
    End Sub

    Private Sub BarButtonItemLastChiTiet_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemLastChiTiet.ItemClick
        Me.NhapchitietBindingSource.MoveLast()
    End Sub

    Private Sub IGridView1_CellValueChanged(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs) Handles IGridView1.CellValueChanged
        Dim view1 As GridView = CType(sender, GridView)
        'If Me.IGridView1.FocusedColumn.FieldName = "mahanghoa" Then
        '    Dim view As DataView = New DataView(Me.PcvgppDataSet.hanghoa_donvitinh)
        '    view.RowFilter = "hanghoa = '" & Me.IGridView1.GetRowCellValue(Me.IGridView1.FocusedRowHandle, "mahanghoa") & "'"
        '    'Me.RepositoryItemSearchLookUpEdit3.DataSource = view
        'End If
        '===================== xử lý thành tiền =======================
        Dim quantity As Decimal = 0
        Dim unitPrice As Decimal = 0
        Try
            quantity = CDec(view1.GetRowCellValue(e.RowHandle, view1.Columns("soluong")))
            unitPrice = CDec(view1.GetRowCellValue(e.RowHandle, view1.Columns("gia")))
        Catch ex As Exception

        End Try

        If e.Column.FieldName = "gia" Then
            view1.SetRowCellValue(e.RowHandle, view1.Columns("thanhtien"), quantity * unitPrice)
        End If
    End Sub

    Private Sub IGridView1_InitNewRow(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Grid.InitNewRowEventArgs) Handles IGridView1.InitNewRow
        If state = 1 Then
            Me.IGridView1.SetFocusedRowCellValue("ma", Me.MaTextEdit.EditValue)
        End If

        Me.IGridView1.SetFocusedRowCellValue("soluong", 0)
        Me.IGridView1.SetFocusedRowCellValue("gia", 0)
        Me.IGridView1.SetFocusedRowCellValue("thanhtien", 0)
    End Sub

    Private Sub NgayhoadonTextEdit_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles NgayhoadonDateEdit.GotFocus
        Me.NgayhoadonDateEdit.ShowPopup()
    End Sub

    Private Sub NgaynhapDateEdit_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles NgaynhapDateEdit.GotFocus
        Me.NgaynhapDateEdit.ShowPopup()
    End Sub

    Private Sub NgaythanhtoanTextEdit_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles NgaythanhtoanDateEdit.GotFocus
        Me.NgaythanhtoanDateEdit.ShowPopup()
    End Sub

    Private Sub BarButtonItemThoat_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemThoat.ItemClick
        Me.Dispose()
        Me.Close()
    End Sub

    Private Sub IGridView1_InvalidValueException(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.InvalidValueExceptionEventArgs) Handles IGridView1.InvalidValueException
        e.ExceptionMode = DevExpress.XtraEditors.Controls.ExceptionMode.DisplayError
    End Sub

    Private Sub IGridView1_InvalidRowException(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.InvalidRowExceptionEventArgs) Handles IGridView1.InvalidRowException
        e.ExceptionMode = DevExpress.XtraEditors.Controls.ExceptionMode.NoAction
    End Sub

    Private Sub IGridView1_ShownEditor(ByVal sender As Object, ByVal e As System.EventArgs) Handles IGridView1.ShownEditor
        Dim view As GridView = CType(sender, GridView)
        If TypeOf view.ActiveEditor Is SearchLookUpEdit And IsDBNull(Me.IGridView1.FocusedValue) Then
            DirectCast(view.ActiveEditor, SearchLookUpEdit).ShowPopup()
        End If
        If TypeOf view.ActiveEditor Is DateEdit And IsDBNull(Me.IGridView1.FocusedValue) Then
            DirectCast(view.ActiveEditor, DateEdit).ShowPopup()
        End If
        Dim view1 As ColumnView = CType(sender, ColumnView)
        view1.ActiveEditor.IsModified = True
    End Sub


    Private Sub IGridView1_ValidatingEditor(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs) Handles IGridView1.ValidatingEditor
        If Me.IGridView1.FocusedColumn.FieldName = "mahanghoa" And IGridView1.FocusedRowHandle <> -999997 Then
            If IsDBNull(e.Value) Or IsNothing(e.Value) Then
                e.ErrorText = "Mã hàng hóa không được rỗng !"
                e.Valid = False
                Exit Sub
            ElseIf e.Value.ToString.Trim = "" Then
                e.ErrorText = "Mã hàng hóa không được rỗng !"
                e.Valid = False
                Exit Sub
            End If
            'If Me.getKiemTraMaTonTai(e.Value) And state = 1 Then
            '    e.ErrorText = "Mã '" & e.Value & "'đã tồn tại !"
            '    e.Valid = False
            'End If
        ElseIf Me.IGridView1.FocusedColumn.FieldName = "tenhanghoa" And IGridView1.FocusedRowHandle <> -999997 Then
            If IsDBNull(e.Value) Or IsNothing(e.Value) Then
                e.ErrorText = "Tên hàng hóa không được rỗng !"
                e.Valid = False
            ElseIf e.Value.ToString.Trim = "" Then
                e.ErrorText = "Tên hàng hóa không được rỗng !"
                e.Valid = False
            End If
            'ElseIf Me.IGridView1.FocusedColumn.FieldName = "madvt" And IGridView1.FocusedRowHandle <> -999997 Then
            '    If IsDBNull(e.Value) Or IsNothing(e.Value) Then
            '        e.ErrorText = "Mã đơn vị tính không được rỗng !"
            '        e.Valid = False
            '    ElseIf e.Value.ToString.Trim = "" Then
            '        e.ErrorText = "Mã đơn vị tính không được rỗng !"
            '        e.Valid = False
            '    End If
        ElseIf Me.IGridView1.FocusedColumn.FieldName = "tendvt" And IGridView1.FocusedRowHandle <> -999997 Then
            If IsDBNull(e.Value) Or IsNothing(e.Value) Then
                e.ErrorText = "Tên đơn vị tính không được rỗng !"
                e.Valid = False
            ElseIf e.Value.ToString.Trim = "" Then
                e.ErrorText = "Tên đơn vị tính không được rỗng !"
                e.Valid = False
            End If
        ElseIf Me.IGridView1.FocusedColumn.FieldName = "soluong" And IGridView1.FocusedRowHandle <> -999997 Then
            If IsDBNull(e.Value) Or IsNothing(e.Value) Then
                e.ErrorText = "Số lượng không được rỗng !"
                e.Valid = False
                Exit Sub
            ElseIf e.Value.ToString.Trim = "" Then
                e.ErrorText = "Số lượngkhông được rỗng !"
                e.Valid = False
                Exit Sub
            ElseIf CDec(e.Value) = 0 Then
                e.ErrorText = "Số lượng không được bằng 0 !"
                e.Valid = False
                Exit Sub
            End If
        ElseIf Me.IGridView1.FocusedColumn.FieldName = "gia" And IGridView1.FocusedRowHandle <> -999997 Then
            If IsDBNull(e.Value) Or IsNothing(e.Value) Then
                e.ErrorText = "Giá không được rỗng !"
                e.Valid = False
                Exit Sub
            ElseIf e.Value.ToString.Trim = "" Then
                e.ErrorText = " Giá không được rỗng !"
                e.Valid = False
                Exit Sub
            ElseIf CDec(e.Value) = 0 Then
                e.ErrorText = "Giá không được bằng 0 !"
                e.Valid = False
                Exit Sub
            End If
        ElseIf Me.IGridView1.FocusedColumn.FieldName = "thanhtien" And IGridView1.FocusedRowHandle <> -999997 Then
            If IsDBNull(e.Value) Or IsNothing(e.Value) Then
                e.ErrorText = "Thành tiền không được rỗng !"
                e.Valid = False
                Exit Sub
            ElseIf e.Value.ToString.Trim = "" Then
                e.ErrorText = "Thành tiền không được rỗng !"
                e.Valid = False
                Exit Sub
            ElseIf CDec(e.Value) = 0 Then
                e.ErrorText = "Thành tiền không được bằng 0 !"
                e.Valid = False
                Exit Sub
            End If
        End If
    End Sub

    Private Sub RepositoryItemSearchLookUpEdit1_EditValueChanging(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.ChangingEventArgs) Handles RepositoryItemSearchLookUpEdit1.EditValueChanging
        Dim editor As SearchLookUpEdit = CType(sender, SearchLookUpEdit)
        Dim rowHandle As Integer = editor.Properties.GetIndexByKeyValue(e.NewValue)
        IGridView1.SetFocusedRowCellValue("tenhanghoa", editor.Properties.View.GetRowCellValue(rowHandle, "ten"))
        IGridView1.SetFocusedRowCellValue("mahanghoa", editor.Properties.View.GetRowCellValue(rowHandle, "ma"))
        IGridView1.SetFocusedRowCellValue("tendvt", editor.Properties.View.GetRowCellValue(rowHandle, "donvitinh"))
    End Sub


    Private Sub BarButtonItemIn_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemIn.ItemClick
        Me.NhapchitietIGridControl.ShowRibbonPrintPreview()
    End Sub

    Private Sub NhacungcapSearchLookUpEdit_EditValueChanging(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.ChangingEventArgs) Handles NhacungcapSearchLookUpEdit.EditValueChanging
        Dim editor As SearchLookUpEdit = CType(sender, SearchLookUpEdit)
        Dim rowhandle As Integer = Me.NhacungcapSearchLookUpEdit.Properties.GetIndexByKeyValue(e.NewValue)
        Me.DiachiTextEdit.EditValue = editor.Properties.View.GetRowCellValue(rowhandle, "diachi")
    End Sub

    Private Sub NhacungcapSearchLookUpEdit_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles NhacungcapSearchLookUpEdit.Enter
        If (state = 1 Or state = 2) And IsDBNull(Me.NhacungcapSearchLookUpEdit.EditValue) Then
            SendKeys.Send("%{DOWN}")
        End If

    End Sub


    Private Sub ThueSuat_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ThuesuatTextEdit.KeyDown
        If state <> 0 And (e.KeyCode = Keys.Enter Or e.KeyCode = Keys.Tab) Then
            Me.NhapBindingSource.EndEdit()
            Me.IGridView1.MoveLast()
            Me.IGridView1.Focus()
            Me.IGridView1.AddNewRow()
            Me.IGridView1.FocusedColumn = Me.IGridView1.VisibleColumns(0)
            Me.IGridView1.ShowEditor()
        End If
    End Sub

    Private Sub NhapchitietIGridControl_ProcessGridKey(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles NhapchitietIGridControl.ProcessGridKey
        If (e.KeyCode = Keys.Enter Or e.KeyCode = Keys.Tab) And (state = 1 Or state = 2) AndAlso Me.IGridView1.FocusedColumn.FieldName.Equals("vitri") Then
            Me.IGridView1.PostEditor()
            Me.IGridView1.UpdateCurrentRow()
            Me.IGridView1.AddNewRow()
            Dim col As GridColumn = IGridView1.Columns("mahanghoa")
            Me.IGridView1.FocusedColumn = col
            Me.IGridView1.ShowEditor()
        End If
    End Sub

    Private Sub ShowGridPreview()
        ' Check whether the XtraGrid control can be previewed. 
        If Not NhapchitietIGridControl.IsPrintingAvailable Then
            MessageBox.Show("The 'DevExpress.XtraPrinting' Library is not found", "Error")
            Return
        End If
        ' Opens the Preview window. 
        'Me.IGridControl1.ShowPrintPreview()
        'IGridControl1.ShowRibbonPrintPreview()
        Me.NhapchitietIGridControl.ShowRibbonPrintPreview()
    End Sub
    
End Class